package com.digitalchina.lxnsy.viewholder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.TrainVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import java.util.List;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2017/3/23 16:18:40
 * 修改备注：
 * ================================================
 */
public class LecturerTrainHolder extends BaseViewHolder<TrainVO> {
    private TextView tvTrainTitle;//培训名称
    private TextView tvEvaluate;//评价按钮 这里不需要
    private SimpleDraweeView ivLecturerHead;//讲师头像
    private TextView tvLecturerName;//讲师名称
    private TextView tvTrainDate;//培训时间
    private TextView tvTrainAddress;//培训地点

    public LecturerTrainHolder(ViewGroup parent) {
        super(parent, R.layout.item_lecturer_train_list);
        tvTrainTitle = $(R.id.item_lecturer_train_tv_title);
        tvEvaluate = $(R.id.item_lecturer_train_tv_evaluate);
        ivLecturerHead = $(R.id.item_lecturer_train_iv_lecturer_head);
        tvLecturerName = $(R.id.item_lecturer_train_tv_lecturer_name);
        tvTrainDate = $(R.id.item_lecturer_train_tv_train_date);
        tvTrainAddress = $(R.id.item_lecturer_train_tv_train_address);
    }

    @Override
    public void setData(TrainVO data) {
        super.setData(data);
        tvTrainTitle.setText(data.getTitle() != null ? data.getTitle() : "");
        tvEvaluate.setVisibility(View.GONE);
        TrainVO.AgriTeacherBean teacherBean = data.getAgriTeacher();

        FrescoUtil.showImageSmall(teacherBean.getImg(), ivLecturerHead);
        tvLecturerName.setText(teacherBean.getName() != null ? teacherBean.getName() : "匿名讲师");

        List<TrainVO.TrainingTimesBean> timesBeens = data.getTrainingTimes();
        String time = "";
//        for (int i = 0; i < timesBeens.size(); i++) {
//            TrainVO.TrainingTimesBean trainTime = timesBeens.get(i);
//            if (i == 0) {
//                time = trainTime.getTrainDate() + " " + trainTime.getStartTime() + "-" + trainTime.getEndTime();
//            } else {
//                time = time + "\n" + trainTime.getTrainDate() + " " + trainTime.getStartTime() + "-" + trainTime.getEndTime();
//            }
//        }

        // 培训时间
        for (int i = 0; i < data.getTrainingTimes().size(); i++) {
            if (i == data.getTrainingTimes().size())
                time += data.getTrainingTimes().get(i).getTrainDate() + " " + data.getTrainingTimes().get(i).getStartTime() + "-" + data.getTrainingTimes().get(i).getEndTime();
            else
                time += data.getTrainingTimes().get(i).getTrainDate() + " " + data.getTrainingTimes().get(i).getStartTime() + "-" + data.getTrainingTimes().get(i).getEndTime() + "\n";
        }


        tvTrainDate.setText(time);
        tvTrainAddress.setText(data.getFullAddress() != null ? data.getFullAddress() : "");
    }
}
